<?php
class PantsPager {
  public $limit;
  public $offset;
  public $page;
  public $total;
  public $totalPages;

  public function __construct($total = 0, $page = 1, $limit = 10) {
    if (!$page || !is_numeric($page) || $page < 1) {
      $page = 1;
    }

    $this->limit      = $limit;
    $this->total      = $total;
    $this->totalPages = $total == 0 ? 1 : ceil($total / $limit);

    if ($page > $this->totalPages) {
      $page = $this->totalPages;
    }

    $this->page   = $page;
    $this->offset = ($this->page - 1) * $this->limit;
  }

  public function hasNext() {
    return $this->page < $this->totalPages;
  }

  public function hasPrev() {
    return $this->page > 1;
  }

  public function prev() {
    if ($this->hasPrev()) {
      return $this->page - 1;
    }

    return $this->page;
  }

  public function next() {
    if ($this->hasNext()) {
      return $this->page + 1;
    }

    return $this->page;
  }
}
?>